## elasticsearch_client.py

from elasticsearch import Elasticsearch, NotFoundError
from typing import Dict, Any, List

class ElasticsearchClient:
    def __init__(self, es: Elasticsearch):
        """Initialize the ElasticsearchClient with an Elasticsearch instance."""
        self.es = es

    def create_index(self, index_name: str, settings: Dict[str, Any], mappings: Dict[str, Any]) -> bool:
        """Create an Elasticsearch index with specified settings and mappings.

        Args:
            index_name: The name of the index to create.
            settings: The settings for the index.
            mappings: The mappings for the index.

        Returns:
            True if the index was created successfully, False otherwise.
        """
        if not self.es.indices.exists(index=index_name):
            self.es.indices.create(index=index_name, body={"settings": settings, "mappings": mappings})
            return True
        return False

    def query_index(self, index_name: str, query: Dict[str, Any]) -> List[Dict[str, Any]]:
        """Query an Elasticsearch index.

        Args:
            index_name: The name of the index to query.
            query: The query to execute.

        Returns:
            A list of documents that match the query.
        """
        try:
            response = self.es.search(index=index_name, body=query)
            return [hit['_source'] for hit in response['hits']['hits']]
        except NotFoundError:
            return []

    def delete_index_entry(self, index_name: str, entry_id: str) -> bool:
        """Delete an entry from an Elasticsearch index.

        Args:
            index_name: The name of the index from which to delete the entry.
            entry_id: The ID of the entry to delete.

        Returns:
            True if the entry was deleted successfully, False otherwise.
        """
        try:
            self.es.delete(index=index_name, id=entry_id)
            return True
        except NotFoundError:
            return False
